package com.estar.assistsurvy.adapter;

import java.util.List;

import com.estar.assistsurvy.R;
import com.estar.assistsurvy.entity.HistoricalCase;
import com.estar.assistsurvy.utils.TimeUtils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class HistoryListAdapter extends BaseAdapter {

	private List<HistoricalCase> historicalCasesList;
	private LayoutInflater inflater;
	public HistoryListAdapter(List<HistoricalCase> historicalCasesList, Context context) {
		super();
		this.historicalCasesList = historicalCasesList;
		inflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return historicalCasesList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return historicalCasesList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView==null){
			holder=new ViewHolder();
			convertView=inflater.inflate(R.layout.listview_history, null);
			holder.carShow=(TextView) convertView.findViewById(R.id.carShow);
			holder.timeShow=(TextView) convertView.findViewById(R.id.timeShow);
			holder.caseState=(TextView) convertView.findViewById(R.id.caseState);
			holder.caseCharge=(TextView) convertView.findViewById(R.id.caseCharge);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		HistoricalCase historicalCase=historicalCasesList.get(position);
		holder.carShow.setText(historicalCase.getTargetCar());
		holder.timeShow.setText(TimeUtils.EnglishToChinese(historicalCase.getGrabTime()));

		switch (Integer.parseInt(historicalCase.getCaseState())) {
		case 1:
			holder.caseState.setText("未抢单");
			break;

		case 2:
			holder.caseState.setText("抢单终止");
			break;

		case 3:
			holder.caseState.setText("已抢单");
			break;

		case 4:
			holder.caseState.setText("已放弃抢单");
			break;

		case 5:
			holder.caseState.setText("已注销");
			break;

		case 6:
			holder.caseState.setText("已完成");
			break;

		default:
			break;
		}
		if(historicalCase.getTotal()!=null){
			holder.caseCharge.setText(historicalCase.getTotal());
		}else{
			holder.caseCharge.setText(historicalCase.getPredictCharge());
		}
		
		return convertView;
	}

	private class ViewHolder{
		private TextView carShow,timeShow,caseState,caseCharge;
	}

}
